﻿<UserControl x:Class="AutoLoL.Controls.MasteryControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Converters="clr-namespace:AutoLoL.Converters" mc:Ignorable="d" 
             x:Name="UserControl"
             Width="34" Height="44" MouseLeftButtonDown="UserControl_MouseLeftButtonDown" MouseRightButtonDown="UserControl_MouseRightButtonDown">

    <!--Tooltip-->
    <UserControl.Resources>
        <Converters:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter" />
        <Converters:MasteryToColorConverter x:Key="MasteryToColorConverter" />
        <Converters:MasteryToPointsRequiredVisibilityConverter x:Key="MasteryToPointsRequiredVisibilityConverter" />
        <Converters:MasteryToPrerequisiteVisibilityConverter x:Key="MasteryToPrerequisiteVisibilityConverter" />
        <SolidColorBrush x:Key="MasteryColor">
            <SolidColorBrush.Color>
                <MultiBinding Converter="{StaticResource MasteryToColorConverter}">
                    <Binding ElementName="UserControl" Path="Mastery" />
                    <Binding ElementName="UserControl" Path="Mastery.CurrentRank" />
                </MultiBinding>
            </SolidColorBrush.Color>
        </SolidColorBrush>
        <ControlTemplate x:Key="ToolTipTemplate" TargetType="ToolTip">
            <Border Width="257" CornerRadius="5" BorderBrush="#FF434343" Background="Black" BorderThickness="2">
                <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
            </Border>
        </ControlTemplate>
    </UserControl.Resources>
    <ToolTipService.ToolTip>
        <ToolTip Template="{StaticResource ToolTipTemplate}" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}">
            <StackPanel Margin="10">
                <!--Title-->
                <TextBlock TextWrapping="Wrap" Text="{Binding Path=Mastery.Name}" Foreground="White" FontSize="16" />

                <!--Current/Max rank-->
                <StackPanel Orientation="Horizontal" >
                    <TextBlock Foreground="{StaticResource MasteryColor}" Text="Rank:" />
                    <TextBlock Foreground="{StaticResource MasteryColor}" Margin="3 0 0 0" Text="{Binding Path=Mastery.CurrentRank}" />
                    <TextBlock Foreground="{StaticResource MasteryColor}" Margin="3 0 0 0" Text="/" />
                    <TextBlock Foreground="{StaticResource MasteryColor}" Margin="3 0 0 0" Text="{Binding Path=Mastery.MaximumRank}" />
                </StackPanel>

                <!--Requires points error-->
                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                    <StackPanel.Visibility>
                        <MultiBinding Converter="{StaticResource MasteryToPointsRequiredVisibilityConverter}">
                            <Binding Path="Mastery" />
                            <Binding Path="Mastery.CurrentRank" />
                        </MultiBinding>
                    </StackPanel.Visibility>
                    <TextBlock Text="Requires" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="{Binding Path=Mastery.PointsToActivate}" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="points in" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="{Binding Path=Mastery.MasteryTree.Name}" Foreground="#FFB40000" />
                </StackPanel>

                <!--Requires prereq error-->
                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                    <StackPanel.Visibility>
                        <MultiBinding Converter="{StaticResource MasteryToPrerequisiteVisibilityConverter}">
                            <Binding Path="Mastery" />
                            <Binding Path="Mastery.CurrentRank" />
                        </MultiBinding>
                    </StackPanel.Visibility>
                    <TextBlock Text="Requires" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="{Binding Path=Mastery.Prerequisite.MaximumRank}" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="points in" Foreground="#FFB40000" />
                    <TextBlock Margin="3 0 0 0" Text="{Binding Path=Mastery.Prerequisite.Name}" Foreground="#FFB40000" />
                </StackPanel>

                <!--Description-->
                <TextBlock TextWrapping="Wrap" Margin="0 5 0 0" Text="{Binding Path=Mastery.CurrentLevelDescription}" Visibility="{Binding Path=Mastery.CurrentLevelDescription, Converter={StaticResource ObjectToVisibilityConverter}}" Foreground="White" />
                <StackPanel Margin="0 5 0 0" Visibility="{Binding Path=Mastery.NextLevelDescription, Converter={StaticResource ObjectToVisibilityConverter}}">
                    <TextBlock TextWrapping="Wrap" Text="Next rank:" Foreground="White"/>
                    <TextBlock TextWrapping="Wrap" Text="{Binding Path=Mastery.NextLevelDescription}" Foreground="White" />
                </StackPanel>
            </StackPanel>
        </ToolTip>
    </ToolTipService.ToolTip>

    <!--Mastery-->
    <Grid>
        <Border BorderBrush="{StaticResource MasteryColor}" BorderThickness="2" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Top" Width="34" Height="34">
            <Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding ElementName=UserControl, Path=Mastery.Image}"/>
        </Border>
        <Border Margin="0 0 3 0" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="26" Height="15" BorderThickness="1" CornerRadius="2">
            <Border.BorderBrush>
                <RadialGradientBrush>
                    <GradientStop Color="#FFF6AC10" Offset="0.997"/>
                    <GradientStop Color="#FFFAD325"/>
                    <GradientStop Color="#FFF7F81A" Offset="0.495"/>
                </RadialGradientBrush>
            </Border.BorderBrush>
            <Grid>
                <Grid.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="Black"/>
                        <GradientStop Color="#FF213852" Offset="0.933"/>
                        <GradientStop Color="Black" Offset="1"/>
                    </LinearGradientBrush>
                </Grid.Background>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
                    <TextBlock FontSize="10" Foreground="{StaticResource MasteryColor}" Text="{Binding ElementName=UserControl, Path=Mastery.CurrentRank}" />
                    <TextBlock FontSize="10" Foreground="{StaticResource MasteryColor}" Text="/" />
                    <TextBlock FontSize="10" Foreground="{StaticResource MasteryColor}" Text="{Binding ElementName=UserControl, Path=Mastery.MaximumRank}" />
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>